package com.jzcn.common.utils;

import com.baomidou.mybatisplus.core.metadata.IPage;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
/**
 * @Author : jz07.cn
 * @CreateTime: 2021-03-02 10:41
 * @Description: 分页组件
 */

public class JzPage<T> implements Serializable {
    private static final long serialVersionUID = 1L;
    private long pageSize = 10L;
    private long pageNum = 1L;
    private List<T> list;
    private long total;

    public JzPage() {
    }

    public JzPage(long pageIndex, long pageSize) {
        this.pageSize = pageSize > 100L ? 100L : pageSize;
        this.pageNum = pageIndex;
    }

    public JzPage(long pageIndex, long pageSize, List<T> list, long total) {
        this.pageSize = pageSize;
        this.pageNum = pageIndex;
        this.list = list;
        this.total = total;
    }

    public JzPage(IPage<T> iPage) {
        this.pageNum = iPage.getCurrent();
        this.pageSize = iPage.getSize();
        this.list = iPage.getRecords();
        this.total = iPage.getTotal();
    }

    public long getPageSize() {
        return this.pageSize;
    }

    public long getPageNum() {
        return this.pageNum;
    }

    public List<T> getList() { return this.list;}

    public long getTotal() {
        return this.total;
    }

    public void setPageSize(long pageSize) {
        this.pageSize = pageSize;
    }

    public void setPageNum(long pageNum) {
        this.pageNum = pageNum;
    }

    public void setList(List<T> list) {
        this.list = list;
    }

    public void setTotal(long total) {
        this.total = total;
    }

    public boolean equals(Object o) {
        if (o == this) {
            return true;
        } else if (!(o instanceof JzPage)) {
            return false;
        } else {
            JzPage<?> other = (JzPage)o;
            if (!other.canEqual(this)) {
                return false;
            } else if (this.getPageSize() != other.getPageSize()) {
                return false;
            } else if (this.getPageNum() != other.getPageNum()) {
                return false;
            } else {
                Object this$list = this.getList();
                Object other$list = other.getList();
                if (this$list == null) {
                    if (other$list == null) {
                        return this.getTotal() == other.getTotal();
                    }
                } else if (this$list.equals(other$list)) {
                    return this.getTotal() == other.getTotal();
                }

                return false;
            }
        }
    }

    protected boolean canEqual(Object other) {
        return other instanceof JzPage;
    }

    public int hashCode() {
        int result = 1;
        long $pageSize = this.getPageSize();
        result = result * 59 + (int)($pageSize >>> 32 ^ $pageSize);
        long $pageNum = this.getPageNum();
        result = result * 59 + (int)($pageNum >>> 32 ^ $pageNum);
        Object $list = this.getList();
        result = result * 59 + ($list == null ? 43 : $list.hashCode());
        long $total = this.getTotal();
        result = result * 59 + (int)($total >>> 32 ^ $total);
        return result;
    }

    public String toString() {
        return "JzPage(pageSize=" + this.getPageSize() + ", pageNum=" + this.getPageNum() + ", list=" + this.getList() + ", total=" + this.getTotal() + ")";
    }
}
